/*
    Borealis Library
    A library of commonly used hydrological modeling building blocks

    Copyright (C) 2008  Chris Marsh

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "RegexTokenizer_UnitTest.h"

CPPUNIT_TEST_SUITE_REGISTRATION( RegExTokenizerTest );



void RegExTokenizerTest::InavildRegEx()
{
	std::string bad_text(1024, ' ');


	token.SetExpression("(.+)+xyz");

	token.Tokenize<std::string>(bad_text);

}

void RegExTokenizerTest::IntLineTest()
{
	std::string line1 = "1 2	3asd		4";
	std::vector<int> items;
	items.clear();

	token.SetExpression("[0-9]+");
	items = token.Tokenize<int>(line1);

	CPPUNIT_ASSERT(items.size() == 4);
	CPPUNIT_ASSERT(items[0] == 1);
	CPPUNIT_ASSERT(items[1] == 2);
	CPPUNIT_ASSERT(items[2] == 3);
	CPPUNIT_ASSERT(items[3] == 4);


}

void RegExTokenizerTest::BadCastLineTest()
{
	std::string line1 = "filename.cpp asdf";
	std::vector<int> items;
	items.clear();

	token.SetExpression("[a-zA-Z]+");
	items = token.Tokenize<int>(line1);

	CPPUNIT_ASSERT(items.size() == 0);
}

void RegExTokenizerTest::DoubleLineTest()
{
	std::string line1 = "1.1 2.2	3.3333asd		4.4";
	std::vector<double> items;
	items.clear();

	token.SetExpression("[0-9]+\\.[0-9]+");
	items = token.Tokenize<double>(line1);

	CPPUNIT_ASSERT(items.size() == 4);
	CPPUNIT_ASSERT(items[0] == 1.1);
	CPPUNIT_ASSERT(items[1] == 2.2);
	CPPUNIT_ASSERT(items[2] == 3.3333);
	CPPUNIT_ASSERT(items[3] == 4.4);

}